package es.castorm.arch.data.config;

import java.util.Map;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;


/**
 * The Class JpaResgistrar.
 */
public class EntityManagerFactoryPostProcessorResgistrar implements ImportBeanDefinitionRegistrar {

	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

		Map<String, Object> annotations = importingClassMetadata.getAnnotationAttributes(EnableJpa.class.getName());
		String[] packagesToScan = (String[]) annotations.get("value");

		BeanDefinitionBuilder beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(EntityManagerFactoryPostProcessor.class);
		beanDefinition.addConstructorArgValue(packagesToScan);
		registry.registerBeanDefinition(EntityManagerFactoryPostProcessor.class.getName(), beanDefinition.getBeanDefinition());
	}
}
